package vip.xiaomaoxiaoke.mpassistant.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.ibatis.type.TypeReference;


@Data
@AllArgsConstructor
@NoArgsConstructor

public class R<T> {

    private Integer code;

    private T data;

    private String msg;




    public static R<Object> buildSuccess() {
        return new R<>(2000, null, null);
    }


    public static  <T> R<T> buildSuccess(String msg,Class<T> tClass) {
        return new R<>(2000, null, msg);
    }

    public static <T> R<T> buildSuccess(TypeReference<T> typeReference, String mgs) {
        return new R<>(2000, null, mgs);
    }
    public static <T> R<T> buildSuccess(T data) {
        return new R<>(2000, data, null);
    }


    public static R<Object> buildError(String msg) {
        return new R<>(5000, null, msg);
    }


    public static <T> R<T> buildError(String msg,Class<T> tClass) {
        return new R<>(5000, null, msg);
    }
    public static <T> R<T> buildError(String mgs,TypeReference<T> typeReference ) {
        return new R<>(5000, null, mgs);
    }


    public static R<Object> buildCodeAndMsg(int code, String msg) {
        return new R<>(code, null, msg);
    }

    public static <T> R<T> buildCodeAndMsg(int code, String msg,Class<T> tClass) {
        return new R<>(code, null, msg);
    }


    public boolean isSuccess() {
        return this.code <3000 && this.code>=2000;
    }


}
